<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.2.1/axios.js"></script>
</head>

<body>
    <button>添加学员</button>
    <button>获取学员</button>
    <ul></ul>
    <script>
        // 获取ul和按钮
        let ul = document.querySelector('ul');
        let btns = document.querySelectorAll('button');


        // axios.defaults.baseURL = 'http://api.zhibao.com:3000'

        //添加学员
        btns[0].onclick =async function(){

            let res = await axios({
                method:"post",
                url:'/students',
                baseURL:'http://api.zhibao.com:3000',
                data:{
                    name:"陈振",
                    age:19,
                    sex:"男"
                },
                params:{
                    name:"chenzhen"
                },
                headers:{
                    // "content-type":'application/x-www-form-urlencoded'
                    a:12
                }
            })

            console.log(res);

        //    let res = await axios.post('/students',{
        //         name:"王凡",
        //         age:18,
        //         sex:"女"
        //     })

        //     console.log(res);
        }

        btns[1].onclick =async function(){
            let res = await axios({
                method:"get",
                url:"/students",
                baseURL:'http://api.zhibao.com:3000',
                data:{

                },
                params:{
                    username:"laowang"
                },
                headers:{
                    b:666
                }
            })

            console.log(res);
        }
    </script>
</body>

</html>